//验证电话号码   格式如 +86(086/0086)-区号(010)-12345678(5到8位)-分机号(3位以上)
function checkPhone(strPhone) { 
	var phoneRegWithArea =/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{5,8})(-(\d{3,}))?$/;
	if( phoneRegWithArea.test(strPhone) ){
		return true; 
	}else{
		return false;
	}
}

//手机号码验证    格式   国外加上国家编号
function checkMobilePhone(strPhone) { 
	var sign = false;
	var phoneRegWithArea =/^(([0\+]\d{2,3}-)?(\d{4,11}))?$/; //国外
	var phoneRegMobile = /^([1]\d{10})?$/;//国内
	if(strPhone.indexOf("-")>0){
		sign = phoneRegWithArea.test(strPhone);
	}else{
		sign = phoneRegMobile.test(strPhone);
	}
	return sign;
}

//1.控制键盘输入，只允许数字键录入整数
function intOnly(object) {
	if(object.value == "-"){
		alert("请输入正整数数字!");
		object.value = "";
	}
	var s = parseInt(object.value);
	if(isNaN(s)){
		alert("请输入正整数数字!");
		object.value = "";
	}else{
	 	object.value = s;
	}
}
//控制键盘输入，只允许数字键录入整数或负数
function intOnlyTwo(object) {
	if(object.value != "-"){
		var s = parseInt(object.value);
	 	if(isNaN(s)){
	 		alert("请输入数字");
	 		object.value = "";
	 	}else{
	 		object.value = s;
	 	}
	}
}
//2.控制键盘输入，只允许数字键录入小数和整数
function numberOnly(object) {
	var st = object.value;
	if(st.indexOf(".")==0){
	 	alert("请输入数字");
	 	object.value = "";
	}else if(st.indexOf(".")+1 == st.length){
	}else{
		var s = parseFloat(st);
		if(isNaN(s)){
	 		alert("请输入数字");
	 		object.value = "";
	 	}
		if(isNaN(object.value)){
			alert("请输入数字");
			object.value = "";
		}
	}
}

//对电子邮件的验证
function checkemail(obj){
	var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if(obj.value!=""){
		if(!myreg.test(obj.value)){
			alert('请输入有效的E_mail！');
			obj.focus();
			return false;
		}else{
			return true;
		}
	}
}
//判断邮政编码格式，格式正确返回true
function checkZip(obj){
	if(obj.value!=""){
		if(obj.value.length!=6){
			alert('请输入有效的邮编！');
			obj.focus();
			return false;
		}else{
			var rexTel=/^[0-9]+$/;
			if(!rexTel.test(obj.value)){
				alert('请输入有效的邮编！');
				obj.focus();
				return false;
			}
		}
	}
	return true;
}


//重新上传文件
function deleteFile(url){
     document.forms[0].attributes["action"].value =url; 
   	 document.forms[0].submit();
}

function deleteInfo(url){
	if(confirm("确定要删除该记录吗?")){window.location=url;}else{return;}
}

//提交验证
function submitInfo() {
	var property; //属性集合
	var message;  //消息集合
	if (propertys!= null && propertys!= ""&&msg!=null&&msg!="") {
		property = propertys.split(",");
		message = msg.split(",");
		for (i = 0; i < property.length; i++) {
			if(document.all[property[i]]!=null){ //是否存在
				var eleObj = document.all[property[i]];	 //对象
				var propertyValue=getPropertyValue(property[i]); //对象值
				var ms="\u662f\u5fc5\u987b\u8f93\u5165\u7684\u9879\u76ee";
				if(propertyValue=="" || propertyValue==null){
					alert(message[i] + ms);
					//转移焦点 
					if (document.all[property[i]].type == "text"||	//文本框
						document.all[property[i]].type == "textarea"|| //文本区
						document.all[property[i]].type == "select-one" //下拉框
						) {
						document.all[property[i]].focus();
					}
					return false;
				}
			}
		}
	} 
	disableFormSelect();
	return true;
}

//提交时让select可编辑
function disableFormSelect(){
	var allElement = document.all;	
	for(var i=0;i<allElement.length;i++){
		if(allElement[i].tagName=="SELECT"){
			allElement[i].disabled=false;
		}
	}
}

 
 //根据属性名得到其页面上的值
function getPropertyValue(propertyName){
	var propertyValue="";
	//如果是单选框
	if(document.all[propertyName].length!=null&&document.all[propertyName][0].type=="radio"){
		for(var i=0;i<document.all[propertyName].length;i++){
			if(document.all[propertyName][i].checked==true) 
				propertyValue = " ";
		}
	}
	//文本框、文本区或下拉框
	else{
		propertyValue=document.all(propertyName).value;
	}
	return propertyValue;
}

//在两个多选下拉框中移动数据
function MoveOptionsTo(oldSelect, newSelect,formName) {
	var myform = document.formName;
	for (i = 0; i < oldSelect.options.length; i++) {
		if (oldSelect.options(i).selected == true) {
			j = newSelect.options.length - 1;
			for (; j >= 0; j--) {
				if (oldSelect.item(i).value == newSelect.item(j).value) {
					break;
				}
			}
			if (j < 0) {
				var name = oldSelect.item(i).text;
				var nameVal=name.split("总数:");
				var total=parseInt(nameVal[1]);
				var newOpt = new Option(nameVal[0], oldSelect.item(i).value);
				if(total==0){
					 alert(nameVal[0]+" 数量为0");
				}else{
					newSelect.add(newOpt);
				}
				
				
			}
		}
	}
}
//删除多选下拉框中指定的数据
function removeItem(from) {
	for (i = from.options.length - 1; i >= 0; i--) {
		if (from.options(i).selected == true) {
			from.remove(i);
		}
	}
}
//向目标多选下拉框中添加指定数据
var coun=0;
function AddAllOptionsTo(oldSelect, newSelect,formName) {
	var myform = document.formName;
	//if(oldSelect.options.length==0){
	//	coun=0;
	//}
	//if(coun==1){
	//	return;
	//}
	for (i = 0; i < oldSelect.options.length; i++) {
		var name = oldSelect.item(i).text;
		var nameVal=name.split("总数:"); //截取  格式：设备名+数量+单位
		var newOpt = new Option(nameVal[0], oldSelect.item(i).value);
		var total=parseInt(nameVal[1]);
		if(total==0){
			alert(nameVal[0]+" 数量为0");
		}else{
			newSelect.add(newOpt);
		}
		
	}
	//coun+=1;
}
//删除多选下拉框 中所有数据
function removeAllItem(from) {
	for (i = from.options.length - 1; i >= 0; i--) {
		from.remove(i);
	}
}
 
function SelectAllOptions(theSelect) {
	for (var i = 0; i < theSelect.options.length; i++) {
		theSelect.options[i].selected = true;
	}
}
/*
  *   功能:实现VBScript的DateAdd功能.
  *   参数:interval,字符串表达式，表示要添加的时间间隔.
  *   参数:number,数值表达式，表示要添加的时间间隔的个数.
  *   参数:date,时间对象.
  *   返回:新的时间对象.
  *   var   now   =   new   Date();
  *   var   newDate   =   DateAdd( "d ",5,now);
  */
function   changeDate(interval,number,date){
	    var temp = date.split('-'); //日期
        switch(interval){
                case   "y"   :   {
                        date.setFullYear(date.getFullYear()+number);
                        return   date;
                        break;
                }
                case   "q"   :   {
                        date.setMonth(date.getMonth()+number*3);
                        return   date;
                        break;
                }
                case   "m"   :   {
                	    var month=temp[1]-1+number*1+1;
                	    alert(month);
                        //date.setMonth(date.getMonth()+number);
                        return new Date(temp[0],month,temp[2]);
                        break;
                }
                case   "w"   :   {
                        date.setDate(date.getDate()+number*7);
                        return   date;
                        break;
                }
                case   "d"   :   {
                	    var day=temp[2]-1+number*1+1;
                	    return new Date(temp[0],temp[1],day);
                       // date.setDate(date.getDate()+number);
                        //return   date;
                        break;
                }
                case   "h"   :   {
                        date.setHours(date.getHours()+number);
                        return   date;
                        break;
                }
                case   "m"   :   {
                        date.setMinutes(date.getMinutes()+number);
                        return   date;
                        break;
                }
                case   "s"   :   {
                        date.setSeconds(date.getSeconds()+number);
                        return   date;
                        break;
                }
                default   :   {
                        date.setDate(d.getDate()+number);
                        return   date;
                        break;
                }
        }
}
/**
 * 日期计算
 * @param {Object} strInterval 操作符
 * @param {Object} Number      数值
 * @param {Object} dateTime    日期
 * @return {TypeName}   日期对象
 */
Date.prototype.DateAdd = function(strInterval,Number,dateTime) {   
    var dtTmp = dateTime;  
    switch (strInterval) {   
        case 's' :return new Date(Date.parse(dtTmp) + (1000 * Number));  
        case 'n' :return new Date(Date.parse(dtTmp) + (60000 * Number));  
        case 'h' :return new Date(Date.parse(dtTmp) + (3600000 * Number));  
        case 'd' :return new Date(Date.parse(dtTmp) + (86400000 * Number));  
        case 'w' :return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));  
        case 'q' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());  
        case 'm' :{
        	 return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()-1) + Number*1+1, dtTmp.getDate()*1, dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
        }
        case 'y' :return new Date((dtTmp.getFullYear() + Number*1), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());  
    }  
}  
/**
 * 将日期转换成字符串 格式为yyyy-MM-dd
 * @param {Object} DateIn 日期对象
 * @return {TypeName} 
 */
function ChangeDateToString(DateIn){
	var Year=0;
	var Month=0;
	var Day=0;
	
	var CurrentDate="";
	
	//初始化时间
	Year = DateIn.getYear();
	Month = DateIn.getMonth();
	Day = DateIn.getDate();
	if(Month==0){
		Month="12";
		Year=Year-1;
	}
	CurrentDate = Year + "-";
	if (Month >= 10 ){
		CurrentDate = CurrentDate + Month + "-";
	}
	else{
		CurrentDate = CurrentDate + "0" + Month + "-";
	}
	if (Day >= 10 ){
		CurrentDate = CurrentDate + Day ;
	}else{
		CurrentDate = CurrentDate + "0" + Day ;
	}
	return CurrentDate;
}




/**
 * 格式化日期对象
 * @return {TypeName} 
 * alert(  DateFormat.format(new Date(),'yyyy年MM月dd日')  );
 */
DateFormat = (function(){      
 var SIGN_REGEXP = /([yMdhsm])(\1*)/g;      
  var DEFAULT_PATTERN = 'yyyy-MM-dd';      
  function padding(s,len){      
   var len =len - (s+'').length;      
  for(var i=0;i<len;i++){s = '0'+ s;}      
   return s;      
 };   
 return({      
   format: function(date,pattern){      
    pattern = pattern||DEFAULT_PATTERN;      
   return pattern.replace(SIGN_REGEXP,function($0){      
     switch($0.charAt(0)){      
      case 'y' : return padding(date.getFullYear(),$0.length);      
     case 'M' : return padding(date.getMonth()+1,$0.length);      
      case 'd' : return padding(date.getDate(),$0.length);      
      case 'w' : return date.getDay()+1;      
     case 'h' : return padding(date.getHours(),$0.length);      
     case 'm' : return padding(date.getMinutes(),$0.length);      
      case 's' : return padding(date.getSeconds(),$0.length);      
     }      
   });      
   },      
   parse: function(dateString,pattern){      
    var matchs1=pattern.match(SIGN_REGEXP);      
    var matchs2=dateString.match(/(\d)+/g);      
   if(matchs1.length==matchs2.length){      
     var _date = new Date(1970,0,1);      
     for(var i=0;i<matchs1.length;i++){   
      var _int = parseInt(matchs2[i]);   
    var sign = matchs1[i];   
     switch(sign.charAt(0)){      
    case 'y' : _date.setFullYear(_int);break;      
     case 'M' : _date.setMonth(_int-1);break;      
     case 'd' : _date.setDate(_int);break;      
    case 'h' : _date.setHours(_int);break;      
     case 'm' : _date.setMinutes(_int);break;      
     case 's' : _date.setSeconds(_int);break;      
    }   
     }      
     return _date;      
   }      
   return null;      
   }      
  });      
  })();     




function calMonth(type,interval,date,number,target){
    var temp = date.split('-'); //日期
    var date1=new Date(); //现在日期
　　 var d=new Date(temp[0],temp[1]-1,temp[2]); //输入的日期,月减1
	var m=temp[1]-1+number*1; 
	var d2 = new Date(temp[0],m,temp[2]);  
	var m=d2.getMonth()+1;
    target.value=d2.getFullYear()+"-"+m+"-"+d2.getDate();
}   
/*
 * 
 * var temp = date.split('-'); //日期
    var date1=new Date(); //现在日期
　　 var d=new Date(temp[0],temp[1]-1,temp[2]); //输入的日期,月减1
    var year="";
    var month=""; 
    var day="";
    var d2=null;
    switch(interval) {
                case   "y"   :   {
                	    year=temp[0]-1+number*1;
                	    d2 = new Date(year,temp[1],temp[2]);
                        year=d2.getFullYear()+1; 
                         d2 = new Date(year,temp[1],temp[2]);
                        break;
                }case   "d"   :   {
                	    day=temp[2]-1+number*1;
                	    d2 = new Date(temp[0],temp[1],day);
                        day=d2.getDate()+1;
                        d2 = new Date(temp[0],temp[1],day);
                        break;
                }case   "m"   :   {
                	    month=temp[1]-1+number*1;
                	    d2 = new Date(temp[0],month,temp[2]);
                        month=d2.getMonth()+1;
                        d2 = new Date(temp[0],month,temp[2]);
                        break;
                }default   :   {
                        //date.setDate(d.getDate()+number);
                       // return   date;
                        break;
                }
        }
    target.value=d2.getFullYear()+"-"+d2.getMonth()+"-"+d2.getDate();
 */